﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Soundteller.Common.Tests;
using Soundteller.Visual.Model;
using Soundteller.Visual.Model.Interfaces;
using Soundteller.Visual.Repositories;
using Soundteller.Visual.Repositories.Interfaces;

namespace Soundteller.Visual.Tests.Unit.Repositories.GraphicRepositorySpecifications
{
    public abstract class WhenGetByName : TestBase
    {
        protected IGraphicRepository GraphicRepository { get; private set; }
        protected Mock<IMemoryContext> MemoryContext { get; private set; }
        protected abstract string Name { get; }
        protected GraphicBase Result { get; private set; }

        protected override void Arrange()
        {
            MemoryContext = new Mock<IMemoryContext>();
            MemoryContext.Setup(c => c.Graphics).Returns(new List<GraphicBase>());

            GraphicRepository = new GraphicRepository(MemoryContext.Object);
        }

        protected override void Act()
        {
            Result = GraphicRepository.GetByName(Name);
        }
    }

    [TestClass]
    public class WhenGetSoundtellerGivenUnknownName : WhenGetByName
    {
        protected override string Name
        {
            get { return Guid.NewGuid().ToString(); }
        }

        [TestMethod]
        public void ThenResultShouldBeNull()
        {
            Assert.IsNull(Result);
        }
    }

    [TestClass]
    public class WhenGetSoundtellerGivenKnownName : WhenGetByName
    {
        protected override string Name
        {
            get { return "unit-test"; }
        }

        protected override void Arrange()
        {
            base.Arrange();
            MemoryContext.Setup(c => c.Graphics).Returns(new List<GraphicBase> { new GeneratedGraphic { Name = Name } });
        }

        [TestMethod]
        public void ThenResultShouldContainName()
        {
            Assert.IsNotNull(Result);
            Assert.AreEqual(Result.Name, Name);
        }
    }
}
